﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;


using WinnerCMS.Data;
using WinnerCMS.Model;
using WinnerCMS.Common;
namespace WinnerCMS.Data
{
    public class MemberScoreDal
    {
        public void Add(UserScore model)
        {
            //SqlParameter[] arrParameter = new SqlParameter[] { new SqlParameter("UserName", SqlDbType.NVarChar, 50), new SqlParameter("CheckIn", SqlDbType.Money, 8), new SqlParameter("CheckInDate", SqlDbType.DateTime), new SqlParameter("Remark", SqlDbType.NVarChar, 100), new SqlParameter("OrderId", SqlDbType.NVarChar, 100) };
            //arrParameter[0].Value = model.UserName;
            //arrParameter[1].Value = model.CheckIn;
            //arrParameter[2].Value = model.CheckInDate;
            //arrParameter[3].Value = model.Remark;
            //arrParameter[4].Value = model.OrderId;

            //SQLBaseV2.ExecuteNonQuery("P_CMS_MemberScore_Add", arrParameter, CommandType.StoredProcedure);

        }

        public UserScore GetMemberScoresInfo(int UserID)
        {
            using (Entities db = new Entities())
            {
                return db.UserScores.Where(x => x.UserId == UserID).OrderByDescending(x => x.Id).FirstOrDefault();
            }
        }


        /// <summary>
        /// 绑定分页数据
        /// </summary>
        /// <param name="pp"></param>
        /// <returns></returns>
        public IList<UserScore> BindList(PagingParam pp)
        {
            using (Entities db = new Entities())
            {
                var query = from x in db.UserScores
                            select x;
                pp.RecordCount = query.Count();

                return query.OrderByDescending(x => x.Id).Skip(pp.Skip).Take(pp.PageSize).ToList();
            }
        }
    }
}
